<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Install OpenCV-Python in Fedora</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d6/d00/tutorial_py_root.html">OpenCV-Python Tutorials</a></li><li class="navelem"><a class="el" href="../../da/df6/tutorial_py_table_of_contents_setup.html">Introduction to OpenCV</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Install OpenCV-Python in Fedora </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Goals </h2>
<p>In this tutorial</p><ul>
<li>We will learn to setup OpenCV-Python in your Fedora system. Below steps are tested for Fedora 18 (64-bit) and Fedora 19 (32-bit).</li>
</ul>
<h2>Introduction </h2>
<p>OpenCV-Python can be installed in Fedora in two ways, 1) Install from pre-built binaries available in fedora repositories, 2) Compile from the source. In this section, we will see both.</p>
<p>Another important thing is the additional libraries required. OpenCV-Python requires only <b>Numpy</b> (in addition to other dependencies, which we will see later). But in this tutorials, we also use <b>Matplotlib</b> for some easy and nice plotting purposes (which I feel much better compared to OpenCV). Matplotlib is optional, but highly recommended. Similarly we will also see <b>IPython</b>, an Interactive Python Terminal, which is also highly recommended.</p>
<h2>Installing OpenCV-Python from Pre-built Binaries </h2>
<p>Install all packages with following command in terminal as root. </p><div class="fragment"><div class="line">$ yum install numpy opencv*</div></div><!-- fragment --><p> Open Python IDLE (or IPython) and type following codes in Python terminal. </p><div class="fragment"><div class="line">&gt;&gt;&gt; <span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</div><div class="line">&gt;&gt;&gt; <a class="code" href="../../df/d57/namespacecv_1_1dnn.html#a701210a0203f2786cbfd04b2bd56da47">print</a>( cv.__version__ )</div></div><!-- fragment --><p> If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.</p>
<p>It is quite easy. But there is a problem with this. Yum repositories may not contain the latest version of OpenCV always. For example, at the time of writing this tutorial, yum repository contains 2.4.5 while latest OpenCV version is 2.4.6. With respect to Python API, latest version will always contain much better support. Also, there may be chance of problems with camera support, video playback etc depending upon the drivers, ffmpeg, gstreamer packages present etc.</p>
<p>So my personal preference is next method, i.e. compiling from source. Also at some point in time, if you want to contribute to OpenCV, you will need this.</p>
<h2>Installing OpenCV from source </h2>
<p>Compiling from source may seem a little complicated at first, but once you succeeded in it, there is nothing complicated.</p>
<p>First we will install some dependencies. Some are compulsory, some are optional. Optional dependencies, you can leave if you don't want.</p>
<h3>Compulsory Dependencies</h3>
<p>We need <b>CMake</b> to configure the installation, <b>GCC</b> for compilation, <b>Python-devel</b> and <b>Numpy</b> for creating Python extensions etc. </p><div class="fragment"><div class="line">yum install cmake</div><div class="line">yum install python-devel numpy</div><div class="line">yum install gcc gcc-c++</div></div><!-- fragment --><p> Next we need <b>GTK</b> support for GUI features, Camera support (libdc1394, v4l), Media Support (ffmpeg, gstreamer) etc. </p><div class="fragment"><div class="line">yum install gtk2-devel</div><div class="line">yum install libdc1394-devel</div><div class="line">yum install ffmpeg-devel</div><div class="line">yum install gstreamer-plugins-base-devel</div></div><!-- fragment --> <h3>Optional Dependencies</h3>
<p>Above dependencies are sufficient to install OpenCV in your fedora machine. But depending upon your requirements, you may need some extra dependencies. A list of such optional dependencies are given below. You can either leave it or install it, your call :)</p>
<p>OpenCV comes with supporting files for image formats like PNG, JPEG, JPEG2000, TIFF, WebP etc. But it may be a little old. If you want to get latest libraries, you can install development files for these formats. </p><div class="fragment"><div class="line">yum install libpng-devel</div><div class="line">yum install libjpeg-turbo-devel</div><div class="line">yum install jasper-devel</div><div class="line">yum install openexr-devel</div><div class="line">yum install libtiff-devel</div><div class="line">yum install libwebp-devel</div></div><!-- fragment --><p> Several OpenCV functions are parallelized with <b>Intel's Threading Building Blocks</b> (TBB). But if you want to enable it, you need to install TBB first. ( Also while configuring installation with CMake, don't forget to pass -D WITH_TBB=ON. More details below.) </p><div class="fragment"><div class="line">yum install tbb-devel</div></div><!-- fragment --><p> OpenCV uses another library <b>Eigen</b> for optimized mathematical operations. So if you have Eigen installed in your system, you can exploit it. ( Also while configuring installation with CMake, don't forget to pass -D WITH_EIGEN=ON. More details below.) </p><div class="fragment"><div class="line">yum install eigen3-devel</div></div><!-- fragment --><p> If you want to build <b>documentation</b> ( <em>Yes, you can create offline version of OpenCV's complete official documentation in your system in HTML with full search facility so that you need not access internet always if any question, and it is quite FAST!!!</em> ), you need to install <b>Doxygen</b> (a documentation generation tool). </p><div class="fragment"><div class="line">yum install doxygen</div></div><!-- fragment --> <h3>Downloading OpenCV</h3>
<p>Next we have to download OpenCV. You can download the latest release of OpenCV from <a href="http://sourceforge.net/projects/opencvlibrary/">sourceforge site</a>. Then extract the folder.</p>
<p>Or you can download latest source from OpenCV's github repo. (If you want to contribute to OpenCV, choose this. It always keeps your OpenCV up-to-date). For that, you need to install <b>Git</b> first. </p><div class="fragment"><div class="line">yum install git</div><div class="line">git clone https://github.com/opencv/opencv.git</div></div><!-- fragment --><p> It will create a folder OpenCV in home directory (or the directory you specify). The cloning may take some time depending upon your internet connection.</p>
<p>Now open a terminal window and navigate to the downloaded OpenCV folder. Create a new build folder and navigate to it. </p><div class="fragment"><div class="line">mkdir build</div><div class="line">cd build</div></div><!-- fragment --> <h3>Configuring and Installing</h3>
<p>Now we have installed all the required dependencies, let's install OpenCV. Installation has to be configured with CMake. It specifies which modules are to be installed, installation path, which additional libraries to be used, whether documentation and examples to be compiled etc. Below command is normally used for configuration (executed from build folder). </p><div class="fragment"><div class="line">cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..</div></div><!-- fragment --><p> It specifies that build type is "Release Mode" and installation path is /usr/local. Observe the -D before each option and .. at the end. In short, this is the format: </p><div class="fragment"><div class="line">cmake [-D &lt;flag&gt;] [-D &lt;flag&gt;] ..</div></div><!-- fragment --><p> You can specify as many flags you want, but each flag should be preceded by -D.</p>
<p>So in this tutorial, we are installing OpenCV with TBB and Eigen support. We also build the documentation, but we exclude Performance tests and building samples. We also disable GPU related modules (since we use OpenCV-Python, we don't need GPU related modules. It saves us some time).</p>
<p>*(All the below commands can be done in a single cmake statement, but it is split here for better understanding.)*</p>
<ul>
<li>Enable TBB and Eigen support: <div class="fragment"><div class="line">cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..</div></div><!-- fragment --></li>
<li>Enable documentation and disable tests and samples <div class="fragment"><div class="line">cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..</div></div><!-- fragment --></li>
<li>Disable all GPU related modules. <div class="fragment"><div class="line">cmake -D WITH_OPENCL=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..</div></div><!-- fragment --></li>
<li>Set installation path and build type <div class="fragment"><div class="line">cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..</div></div><!-- fragment --> Each time you enter cmake statement, it prints out the resulting configuration setup. In the final setup you got, make sure that following fields are filled (below is the some important parts of configuration I got). These fields should be filled appropriately in your system also. Otherwise some problem has happened. So check if you have correctly performed above steps. <div class="fragment"><div class="line">...</div><div class="line">--   GUI:</div><div class="line">--     GTK+ 2.x:                    YES (ver 2.24.19)</div><div class="line">--     GThread :                    YES (ver 2.36.3)</div><div class="line"></div><div class="line">--   Video I/O:</div><div class="line">--     DC1394 2.x:                  YES (ver 2.2.0)</div><div class="line">--     FFMPEG:                      YES</div><div class="line">--       codec:                     YES (ver 54.92.100)</div><div class="line">--       format:                    YES (ver 54.63.104)</div><div class="line">--       util:                      YES (ver 52.18.100)</div><div class="line">--       swscale:                   YES (ver 2.2.100)</div><div class="line">--       gentoo-style:              YES</div><div class="line">--     GStreamer:</div><div class="line">--       base:                      YES (ver 0.10.36)</div><div class="line">--       video:                     YES (ver 0.10.36)</div><div class="line">--       app:                       YES (ver 0.10.36)</div><div class="line">--       riff:                      YES (ver 0.10.36)</div><div class="line">--       pbutils:                   YES (ver 0.10.36)</div><div class="line"></div><div class="line">--     V4L/V4L2:                    Using libv4l (ver 1.0.0)</div><div class="line"></div><div class="line">--   Other third-party libraries:</div><div class="line">--     Use Eigen:                   YES (ver 3.1.4)</div><div class="line">--     Use TBB:                     YES (ver 4.0 interface 6004)</div><div class="line"></div><div class="line">--   Python:</div><div class="line">--     Interpreter:                 /usr/bin/python2 (ver 2.7.5)</div><div class="line">--     Libraries:                   /lib/libpython2.7.so (ver 2.7.5)</div><div class="line">--     numpy:                       /usr/lib/python2.7/site-packages/numpy/core/include (ver 1.7.1)</div><div class="line">--     packages path:               lib/python2.7/site-packages</div><div class="line"></div><div class="line">...</div></div><!-- fragment --> Many other flags and settings are there. It is left for you for further exploration.</li>
</ul>
<p>Now you build the files using make command and install it using make install command. make install should be executed as root. </p><div class="fragment"><div class="line">make</div><div class="line">su</div><div class="line">make install</div></div><!-- fragment --><p> Installation is over. All files are installed in /usr/local/ folder. But to use it, your Python should be able to find OpenCV module. You have two options for that.</p>
<ol type="1">
<li><b>Move the module to any folder in Python Path</b> : Python path can be found out by entering <code>import sys; print(sys.path)</code> in Python terminal. It will print out many locations. Move /usr/local/lib/python2.7/site-packages/cv2.so to any of this folder. For example, <div class="fragment"><div class="line">su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages</div></div><!-- fragment --> But you will have to do this every time you install OpenCV.</li>
<li><b>Add /usr/local/lib/python2.7/site-packages to the PYTHON_PATH</b>: It is to be done only once. Just open/.bashrc and add following line to it, then log out and come back. <div class="fragment"><div class="line">export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages</div></div><!-- fragment --> Thus OpenCV installation is finished. Open a terminal and try 'import cv2 as cv'.</li>
</ol>
<p>To build the documentation, just enter following commands: </p><div class="fragment"><div class="line">make doxygen</div></div><!-- fragment --><p> Then open opencv/build/doc/doxygen/html/index.html and bookmark it in the browser.</p>
<h2>Additional Resources </h2>
<h2>Exercises </h2>
<ol type="1">
<li>Compile OpenCV from source in your Fedora machine. </li>
</ol>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:37 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
